(function ($) {
	$.fn.fadeAffect = function(options) {
	  var options = $.extend({pauseTime: 5500, transitionTime: 500}, options);
	  var transitionObject;
      var _effected = false;

	  Trans = function(obj) {
		var timer = null;
		var current = 0;
		var els = $("> *", obj).css("display", "none").css("left", "0").css("top", "0").css("position", "absolute");
		$(obj).css("position", "relative");
		$(els[current]).css("display", "block");

		function transition(next) {
		  $(els[current]).fadeOut(options.transitionTime);
          $(els[next]).fadeIn(options.transitionTime);
		  current = next;
		  cue();
		};

		function cue() {
		  if ($("> *", obj).length < 2) return false;
		  if (timer) { clearTimeout(timer); }
		  timer = setTimeout(function() { transition((current + 1) % els.length | 0)} , options.pauseTime);
		};

		this.showItem = function(item) {
		  if (timer) { clearTimeout(timer); }
		  transition(item);
		};
       
        this.getCurrentIndex = function() {
          return current;
        };

        this.getCurrentItem = function() {
          return $(els[current]);
        };

        this.stop = function() {
		  if (timer) clearTimeout(timer);
        };

        this.getItemByIndex = function(_idx) {
          if (_idx < els.length) {
            return $(els[_idx]);
          }
          return null;
        };

		cue();
	  }

	  this.showItem = function(item) {
		transitionObject.showItem(item);
	  };

      this.getCurrentItem = function() {
        return transitionObject.getCurrentItem();
      };

      this.getItemByIndex = function(_idx) {
        return transitionObject.getItemByIndex(_idx);
      };

      this.getCurrentIndex = function() {
        return transitionObject.getCurrentIndex();
      };

      this.stop = function() {
        transitionObject.stop();
      };

	  return this.each(function() {
			transitionObject = new Trans(this);
	  });
	}

})(jQuery);

